package com.skyline.base.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.skyline.base.model.Site;
import com.skyline.base.service.SiteService;

/**
 * 地点模块的Controller 主要功能为提供各级行政区域的查询
 * 
 * @author Jairus Chan
 * @version 0.1
 * */
@Controller
@RequestMapping("/site")
public class SiteController {
	@Autowired
	private SiteService siteService;

	/**
	 * 获取所有的国家<br>
	 * 行政区域分以下几个等级:<br>
	 * 1.country 国家<br>
	 * 2.province 省／州<br>
	 * 3.city 城市<br>
	 * 4.county 区<br>
	 * 
	 * @return
	 */
	@RequestMapping("/getCountries")
	public @ResponseBody
	List<Site> getCountries() {
		try {
			List<Site> countries = siteService.getAllCountries();
			return countries;

		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 获取下一级的行政区域
	 * 
	 * @param siteId
	 * @return
	 */
	@RequestMapping("/getSubSites")
	public @ResponseBody
	List<Site> getSubSites(String siteId) {
		try {
			List<Site> sites = siteService.getSubSites(siteId);// .getAllCountries();
			return sites;

		} catch (Exception e) {
			return null;
		}
	}

}
